package com.situ.onlinebookstore.back.config;

import com.situ.onlinebookstore.back.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Value("${upload.path}")
    private String path;

    @Autowired  //spring 5.x版本不推荐了

    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/css/**",
                        "/img/**",
                        "/js/**",
                        "/layui/**",
//                        "/html/admin/login.html",
                        "/verCode",
                        "/admin/login"
                );

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //添加静态资源的映射路径
        registry.addResourceHandler("/upload/**")
                .addResourceLocations("file:"+path);
    }
}
